package com.kuang.service;

import com.kuang.dao.BookMapper;
import com.kuang.dao.BorrowMapper;
import com.kuang.pojo.Borrows;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BorrowServiceimpl implements BorrowService {
    @Autowired
    BookMapper bookMapper;
    @Autowired
    BorrowMapper borrowMapper;

    public void setBorrowMapper(BorrowMapper borrowMapper) {
        this.borrowMapper = borrowMapper;
    }

    public int addBorrow(Borrows borrows) {
        bookMapper.updateBookNumber(borrows.getBorrowNumber(),borrows.getBookNo());
        return borrowMapper.addBorrow(borrows);
    }

    public List<Borrows> queryAllBorrow() {
        return borrowMapper.queryAllBorrow();
    }

    public int deleteBorrowById(int id) {
        bookMapper.updateBookNumber2(id);
        return borrowMapper.deleteBorrowById(id);
    }

    public int updateBorrowById(int id) {
        bookMapper.updateBookNumber2(id);
        return borrowMapper.updateBorrowById(id);
    }

    public Borrows queryBorrowById(int id){
        return borrowMapper.queryBorrowById(id);
    }

    public int updateBorrow(Borrows borrows) {
        bookMapper.updateBookById2(borrows);
        return borrowMapper.updateBorrow(borrows);
    }


    public List<Borrows> queryAllNo(String queryReadersNo){
        return borrowMapper.queryAllNo(queryReadersNo);
    }
}
